<!--
 * @Author: wang cong wangc9832@163.com
 * @Date: 2023-10-12 09:22:21
 * @LastEditors: wang cong wangc9832@163.com
 * @LastEditTime: 2023-10-20 14:34:55
 * @FilePath: /ams_product_front/src/components/Form/src/busComponents/RoleOrgSelect.vue
 * @Description: 
 * 
 * Copyright (c) 2023 by ${git_name_email}, All Rights Reserved. 
-->
<template>
  <ApiSelect v-bind="$attrs" numberToString :api="api" @change="handleChange" />
</template>
<script setup lang="ts">
import ApiSelect from '../components/ApiSelect.vue';
import { getUserRoleOrg } from '@/api/sys/busComponentManage';
import { useUserStore } from '@/store/modules/user';
const userStore = useUserStore();
const emit = defineEmits(['change', 'update:value']);
type OptionsItem = { label: string; value: string; disabled?: boolean };
const api = getUserRoleOrg as unknown as PropType<
  (arg?: Recordable) => Promise<OptionsItem[]>
>;
const handleChange = (v) => {
  const orgs = userStore.getOrgs;
  const org = orgs.find((o) => o.id === v) as Recordable;
  emit('change', v, org ? org.roleId?.split(',') : []);
};
</script>
